package com.cjzuji.rental.dao.impl;

import com.cjzuji.rental.controller.order.YouPinController;
import com.cjzuji.rental.dao.AiDouUserDao;
import com.cjzuji.rental.mapper.OrderUserMapper;
import com.cjzuji.rental.pojo.OrderUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.Map;
@Service
public class AiDouUserDaoImpl implements AiDouUserDao {

    private static final Logger logger = LoggerFactory.getLogger(YouPinController.class);
    @Autowired
    OrderUserMapper orderUserMapper;

    @Override
    @Transactional
    public  void save( Map<String, Object> item,Map<String,Object> detail, Long orderID) {
        String phone = "";
        if(item.get("consigneeMobile") != null){
            phone = item.get("consigneeMobile").toString();
        }
        OrderUser aiZUJiOrderUser = OrderUser.builder()
                .orderId(orderID)
                .userName(detail.get("authName").toString())  //收货人
                .mobile(phone)
                .province("")
                .city("")
                .county("")
                .address("")
                .addressInfo(detail.get("consigneeDetail").toString())
                .idCard(detail.get("idCard").toString())
                .idCardName(detail.get("authName").toString())
                .idCardImg("")
                .idCardBlackImg("")
                .faceImg("")
                .createTime(new Date())
                .updateTime(new Date())
                .build();
        //logger.info("打印添加参数order_user {}",aiZUJiOrderUser);
        try {
            orderUserMapper.insert(aiZUJiOrderUser);
        }catch (Exception e){
            logger.info("订单用户添加错误" + e.getMessage());
            throw e; // 重新抛出，确保事务回滚
        }
    }
}
